package com.dj.shop.service.impl;

import com.dj.shop.mapper.GoodsClassMapper;
import com.dj.shop.model.GoodsClass;
import com.dj.shop.service.GoodClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

@Service
public class GoodClassServiceImpl implements GoodClassService {

        @Autowired
        private GoodsClassMapper goodsClassMapper;

        @Override
        public int insert(Set<GoodsClass> rowCell) {
            for (GoodsClass goodsClass:rowCell){
                if(goodsClass.getclassLevel().indexOf(".") > 0){
                    goodsClass.setclassLevel(goodsClass.getclassLevel().replaceAll("0+?$", ""));
                    goodsClass.setclassLevel(goodsClass.getclassLevel().replaceAll("[.]$", ""));
                }

                goodsClass.setclassLevel(goodsClass.getclassLevel().trim());
                     goodsClassMapper.insertSelective(goodsClass);
            }
            return 1;

    }

}
